home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Franz PD / Franz PD Disk #045 (1990)(Amiga User Group Deutschland e.V.).zip / Franz PD Disk #045 (1990)(Amiga User Group Deutschland e.V.).adf / AtoI&ItoA / ItoA.c < prev   
C/C++ Source or Header  |  1989-07-02  |  3KB  |  145 lines

  1. /* ItoA - wandelt IBM-Textfiles in AMIGA-Textfiles um.
  2.    Das Problem: Der IBM benutzt andere ASCII-Codes als der AMIGA. Dies macht
  3.    sich vor allem bei den deutschen Umlauten und dem ß bemerkbar.
  4.    Dieses Programm behandelt einen mit AWRITE auf AMIGA-Seite gebrachten Text
  5.    nach. Syntax:
  6.    ItoA <IBMfile> <AMIGAfile>
  7.    <IBMfile>   : Filename des umzuwandelnden Textes
  8.    <AMIGAfile> : Filename des zu erstellenden Textes
  9.  
  10.    23.3.1989 Tim Pietzcker Software
  11.  
  12.    Kopieren, Ergänzen, Verstümmeln etc. erwünscht.
  13. */
  14.  
  15. #include <exec/types.h>
  16. #include <exec/memory.h>
  17. #include <libraries/dos.h>
  18.  
  19. #define CONVTBLENGTH 14        /* wenn die Tabelle erweitert wird, einfach
  20.                    neue Anzahl hier eintragen */
  21. #define BUFSIZE      4096l
  22.  
  23. struct Library    *OpenLibrary();
  24. struct DosBase    *DosBase;
  25. struct FileHandle *source,*dest,*Open();
  26. UBYTE          *buffer,*sourcename,*destname,*AllocMem();
  27. UBYTE          ConvTable[] =
  28.           /* links IBM,rechts AMIGA */
  29.             { 142,196,    /* Ä */
  30.               153,214,    /* Ö */
  31.               154,220,    /* Ü */
  32.               132,228,    /* ä */
  33.               148,246,    /* ö */
  34.               129,252,    /* ü */
  35.               225,223 };    /* ß */
  36. LONG          len;
  37.  
  38. open_files(src,dst)
  39. UBYTE *src,*dst;
  40. {
  41.    source=Open(src,MODE_OLDFILE);
  42.    if (source==NULL) 
  43.    {
  44.       printf("Unable to open source file : %s\n",src);
  45.       get_out();
  46.    }
  47.    dest=Open(dst,MODE_NEWFILE);
  48.    if (dest==NULL)
  49.    {
  50.       printf("Unable to open destination file : %s\n",dst);
  51.       get_out();
  52.    }
  53. }
  54.  
  55. get_out()
  56. {
  57.    if (DosBase) CloseLibrary(DosBase);
  58.    if (source)  Close(source);
  59.    if (dest)    Close(dest);
  60.    if (buffer)  FreeMem(buffer,BUFSIZE);
  61.    exit(TRUE);
  62. }
  63.  
  64. convert_block(buf,length) /* wandelt einen Block von BUFSIZE Bytes oder weniger
  65.                  ins richtige Format um */
  66. UBYTE *buf;
  67. LONG length;
  68. {
  69.    UBYTE *ptr;
  70.    LONG i;
  71.    int j;
  72.    for(ptr=buf,i=0;i<length;++i,++ptr)
  73.       if(*ptr & 0x80) /* ASCII-Code > 128 ? */
  74.          for(j=0;j < CONVTBLENGTH; j+=2)    /* Tabelle absuchen */
  75.         if(*ptr == ConvTable[j]) *ptr=ConvTable[j+1];
  76.  
  77.    i=Write(dest,buf,length);
  78.    if (i<0)
  79.    {
  80.       printf("Error writing destination file !\n");
  81.       get_out();
  82.    }
  83. }
  84.  
  85. convert_texts()
  86. {
  87.    long done=FALSE;
  88.    while(done==FALSE)    /* solange, bis EOF erreicht */
  89.    {
  90.       len=Read(source,buffer,BUFSIZE);
  91.       if (len<=0)    /* Error oder fertig ? */
  92.       {
  93.          if (len<0)
  94.          {
  95.             printf("Error reading source file !\n");
  96.         get_out();
  97.          }
  98.          done=TRUE;
  99.       }   
  100.       else
  101.          convert_block(buffer,len);
  102.    }
  103. }
  104.  
  105. open_dos()
  106. {
  107.    DosBase=(struct DosBase *)OpenLibrary("dos.library",0l);
  108.    if (DosBase==NULL) exit(FALSE);
  109.    buffer=AllocMem(BUFSIZE,MEMF_CLEAR); 
  110.    if (buffer==NULL)
  111.    {
  112.       printf("Out of Memory !\n");
  113.       get_out();
  114.    }
  115. }
  116.  
  117. usage(filename)        /* erklärt die korrekte Syntax bei Fehlaufruf */
  118. UBYTE *filename;
  119. {
  120.    printf("USAGE : %s <IBMfile> <AMIGAfile>\n",filename);
  121.    printf("\n<IBMfile>   : Name of the text file still in IBM format.\n");
  122.    printf("              This is a file which has been converted to AMIGA DOS");
  123.    printf(" by the                  IBM command AWRITE (see PC manual)");
  124.    printf("\n<AMIGAfile> : Name of the destination file name.\n");
  125.    exit(FALSE);
  126. }
  127.  
  128. main(argc,argv)
  129. int argc;
  130. UBYTE *argv[];
  131. {
  132.    /* Testen, ob Aufruf korrekt */
  133.    if (argc<2 || argc>3 || argc==2 && *argv[1]=='?') usage(argv[0]);
  134.    open_dos();
  135.    sourcename = argv[1];
  136.    destname   = argv[2];
  137.    
  138.    open_files(sourcename,destname);
  139.    
  140.    convert_texts();
  141.    get_out();
  142. }
  143.  
  144. /* End of Source */
  145.